/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * cambioPrueba.java
 *
 * Created on 15-11-2011, 09:37:28 AM
 */
package androidutal;

import java.awt.BorderLayout;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JComboBox;
import javax.swing.JOptionPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

/**
 *
 * @author Roberto
 */
public class JPanelSolicitudAyudante extends javax.swing.JPanel {
    private  JVentana ventana;
    private  String[] profesores;
    private  String[] cursos;
    private boolean isBorrador;

    /** Creates new form cambioPrueba */
    public JPanelSolicitudAyudante(JVentana ventana) {
        Datos datos;      
        try {
            datos = new Datos();
             this.profesores= datos.getProfe();
             this.cursos= datos.getCurso();
        } catch (FileNotFoundException ex) {
            Logger.getLogger(JPanelSolicitudAyudante.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(JPanelSolicitudAyudante.class.getName()).log(Level.SEVERE, null, ex);
        }
        initComponents();
        this.ventana= ventana;
        this.isBorrador = false;
    }
    public boolean isBorrador() {
        return isBorrador;
    }
    public void setIsBorrador(boolean isBorrador) {
        this.isBorrador = isBorrador;
    }
    public JComboBox getjCursos() {
        return jCursos;
    }

    public void setjCursos(JComboBox jCursos) {
        this.jCursos = jCursos;
    }

    public JTextField getjHoras() {
        return jHoras;
    }

    public void setjHoras(JTextField jHoras) {
        this.jHoras = jHoras;
    }

    public JTextArea getjObservaciones() {
        return jObservaciones;
    }

    public void setjObservaciones(JTextArea jObservaciones) {
        this.jObservaciones = jObservaciones;
    }

    public JComboBox getjProfesores() {
        return jProfesores;
    }

    public void setjProfesores(JComboBox jProfesores) {
        this.jProfesores = jProfesores;
    }

    public JTextArea getjRequisitos() {
        return jRequisitos;
    }

    public void setjRequisitos(JTextArea jRequisitos) {
        this.jRequisitos = jRequisitos;
    }
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jObservaciones = new javax.swing.JTextArea();
        jProfesores = new javax.swing.JComboBox(this.profesores);
        jLabel4 = new javax.swing.JLabel();
        jCursos = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jRequisitos = new javax.swing.JTextArea();
        jPanel1 = new javax.swing.JPanel();
        jButton2 = new javax.swing.JButton();
        jButton1 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        jHoras = new javax.swing.JTextField(new Integer(3));
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jScrollPane1.setViewportView(jTextArea1);

        setBackground(new java.awt.Color(0, 0, 0));

        jLabel1.setForeground(new java.awt.Color(255, 255, 255));
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("Solicitud Ayudante");

        jObservaciones.setColumns(20);
        jObservaciones.setLineWrap(true);
        jObservaciones.setRows(5);
        jObservaciones.setWrapStyleWord(true);
        jScrollPane2.setViewportView(jObservaciones);

        jProfesores.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jProfesoresActionPerformed(evt);
            }
        });

        jLabel4.setForeground(new java.awt.Color(255, 255, 255));
        jLabel4.setText("Profesor:");

        jCursos.setModel(new javax.swing.DefaultComboBoxModel(this.cursos));
        jCursos.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCursosActionPerformed(evt);
            }
        });

        jLabel3.setForeground(new java.awt.Color(255, 255, 255));
        jLabel3.setText("Curso: ");

        jLabel2.setForeground(java.awt.Color.white);
        jLabel2.setText("Obs:");

        jLabel5.setForeground(java.awt.Color.white);
        jLabel5.setText("Requisitos:");

        jRequisitos.setColumns(20);
        jRequisitos.setLineWrap(true);
        jRequisitos.setRows(5);
        jRequisitos.setWrapStyleWord(true);
        jScrollPane3.setViewportView(jRequisitos);

        jPanel1.setBackground(java.awt.Color.black);

        jButton2.setBackground(java.awt.Color.white);
        jButton2.setText("Borrador");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton1.setBackground(java.awt.Color.white);
        jButton1.setText("Publicar");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton3.setBackground(java.awt.Color.white);
        jButton3.setText("Cancelar");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addComponent(jButton2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 205, Short.MAX_VALUE)
                .addComponent(jButton1)
                .addGap(18, 18, 18)
                .addComponent(jButton3))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jButton3)
                .addComponent(jButton1)
                .addComponent(jButton2))
        );

        jLabel6.setForeground(new java.awt.Color(255, 255, 255));
        jLabel6.setText("N° de horas:");

        jHoras.setEditable(false);
        jHoras.setText("0");

        jButton4.setText("+");
        jButton4.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                jButton4MouseEntered(evt);
            }
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jButton4MousePressed(evt);
            }
        });
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton5.setText("-");
        jButton5.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                jButton5MousePressed(evt);
            }
        });
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jLabel5, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                        .addGap(26, 26, 26)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 343, Short.MAX_VALUE)
                            .addComponent(jScrollPane2, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 343, Short.MAX_VALUE)))
                    .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 432, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jLabel6)
                        .addGap(18, 18, 18)
                        .addComponent(jHoras, javax.swing.GroupLayout.DEFAULT_SIZE, 245, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton5))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel4)
                            .addComponent(jLabel3))
                        .addGap(34, 34, 34)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(jCursos, 0, 343, Short.MAX_VALUE)
                            .addComponent(jProfesores, javax.swing.GroupLayout.Alignment.LEADING, 0, 343, Short.MAX_VALUE))))
                .addContainerGap())
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(11, 11, 11)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jProfesores, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel4))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jCursos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3))
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addComponent(jLabel6))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(10, 10, 10)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jHoras, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jButton4)
                            .addComponent(jButton5))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel5)
                    .addComponent(jScrollPane3, javax.swing.GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE)
                        .addGap(29, 29, 29))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)))
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
    }// </editor-fold>//GEN-END:initComponents

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// TODO add your handling code here:
    if(!jHoras.getText().equals("0") && !jObservaciones.getText().equals("") && !jRequisitos.getText().equals("")){
        if(this.isBorrador)
               this.ventana.getResumen().eliminarFila();
        ventana.getBaseDeDatos().addAyudante((String)jProfesores.getSelectedItem(),(String)jCursos.getSelectedItem(),
                Integer.valueOf(jHoras.getText()),jRequisitos.getText(), jObservaciones.getText(),false);
        Date date=new Date();
        ventana.getResumen().insertarInfo((String)jCursos.getSelectedItem(),date.toString() ,"No");
        this.setVisible(false);
        ventana.add(ventana.getResumen(),BorderLayout.CENTER);
        ventana.getResumen().setVisible(true);
        ventana.save();
        ventana.saveToWS();
    }
    else{
        JOptionPane.showMessageDialog(this, "Rellene todos los campos obligatorios");
    }
}//GEN-LAST:event_jButton1ActionPerformed

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
// TODO add your handling code here:
    if(this.isBorrador()){
        this.jButton2ActionPerformed(evt);
        this.ventana.getResumen().eliminarFila();
       if(!jHoras.getText().equals("0") && !jObservaciones.getText().equals("") && !jRequisitos.getText().equals("")){        
            this.setVisible(false);
            ventana.add(ventana.getResumen(),BorderLayout.CENTER);
            ventana.getResumen().setVisible(true); 
       }
    }
    else{
            this.setVisible(false);
            ventana.add(ventana.getResumen(),BorderLayout.CENTER);
            ventana.getResumen().setVisible(true); 
    }
    this.desbloquear();
}//GEN-LAST:event_jButton3ActionPerformed

private void jProfesoresActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jProfesoresActionPerformed
// TODO add your handling code here:
    
}//GEN-LAST:event_jProfesoresActionPerformed

private void jCursosActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCursosActionPerformed
// TODO add your handling code here:
    
}//GEN-LAST:event_jCursosActionPerformed

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
// TODO add your handling code here:
    
}//GEN-LAST:event_jButton4ActionPerformed

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
// TODO add your handling code here:
    
}//GEN-LAST:event_jButton5ActionPerformed

private void jButton4MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton4MousePressed
// TODO add your handling code here:
    
    int horas =Integer.parseInt(jHoras.getText());
    horas+=1;
    this.jHoras.setText(String.valueOf(horas));
    
}//GEN-LAST:event_jButton4MousePressed

private void jButton4MouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton4MouseEntered
// TODO add your handling code here:
   
}//GEN-LAST:event_jButton4MouseEntered

private void jButton5MousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jButton5MousePressed
// TODO add your handling code here:
    int horas =Integer.parseInt(jHoras.getText());
    if (horas>0)
    {
        horas-=1;
        this.jHoras.setText(String.valueOf(horas));
    }
    
    
}//GEN-LAST:event_jButton5MousePressed

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
// TODO add your handling code here:
        ventana.getBaseDeDatos().addAyudante((String)jProfesores.getSelectedItem(),(String)jCursos.getSelectedItem(),
                Integer.valueOf(jHoras.getText()),jRequisitos.getText(), jObservaciones.getText(),true);
        Date date=new Date();
        ventana.getResumen().insertarInfo((String)jCursos.getSelectedItem(),date.toString(),"Si" );
        this.setVisible(false);
        ventana.add(ventana.getResumen(),BorderLayout.CENTER);
        ventana.getResumen().setVisible(true);
        ventana.save();
}//GEN-LAST:event_jButton2ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JComboBox jCursos;
    private javax.swing.JTextField jHoras;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JTextArea jObservaciones;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JComboBox jProfesores;
    private javax.swing.JTextArea jRequisitos;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JTextArea jTextArea1;
    // End of variables declaration//GEN-END:variables

    public void bloquear(){
        this.getjCursos().setEnabled(false);
        this.getjHoras().setEditable(false);
        this.getjObservaciones().setEditable(false);
        this.getjProfesores().setEnabled(false);
        this.getjRequisitos().setEditable(false);
        this.jButton1.setVisible(false);
        this.jButton2.setVisible(false);
        this.jButton4.setVisible(false);
        this.jButton5.setVisible(false);
    }
    
    public void desbloquear(){
        this.getjCursos().setEnabled(true);
        this.getjHoras().setEditable(true);
        this.getjObservaciones().setEditable(true);
        this.getjProfesores().setEnabled(true);
        this.getjRequisitos().setEditable(true);
        this.jButton1.setVisible(true);
        this.jButton2.setVisible(true);
        this.jButton4.setVisible(true);
        this.jButton5.setVisible(true);
    }

}
